package com.bnlr.lrparking.appui.unused;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bnlr.lrparking.app.Application;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.base.BaseActivity;
import com.bnlr.lrparking.app.AppConfig;
import com.bnlr.lrparking.constant.LrConstant;
import com.bnlr.lrparking.constant.Urls;
import com.bnlr.lrparking.util.CommonUtil;
import com.bnlr.nohttp.CallServer;
import com.bnlr.nohttp.CustomHttpListener;
import com.yolanda.nohttp.NoHttp;
import org.json.JSONObject;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/3/2.
 * 发布协议界面
 */

public class AtomPubActivity extends BaseActivity {

    @BindView(R.id.wv)
    WebView web;
    @BindView(R.id.activity_web)
    LinearLayout activityWeb;
    @BindView(R.id.tv_nav_title)
    TextView tvNavTitle;
    private String content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        ButterKnife.bind(this);
        tvNavTitle.setText("利人停车-发布信息服务协议");
        getData();

    }

    public void setUrl(String Url) {
        web.loadUrl(Url);
        web.getSettings().setJavaScriptEnabled(true);

    }


    @Override
    public void getData() {
        super.getData();
        try{
            mRequest = NoHttp.createStringRequest(Urls.IP, LrConstant.POST);
            mRequest.add("phonePara", Application.DEVICE_ID);
            mRequest.add("uid", AppConfig.getInstance().getString("uid", ""));
            mRequest.add("action", "GetWenZhang");
            mRequest.add("ca", "58");
            Log.e("打印",Application.DEVICE_ID +"***"+AppConfig.getInstance().getString("uid", ""));
            // 添加到请求队列
            CallServer.getRequestInstance().add(baseContext, mRequest,
                    new CustomHttpListener<JSONObject>(baseContext, true, JSONObject.class) {
                        @Override
                        public void doWork(JSONObject data, String code) {
                        }

                        @Override
                        public void onFinally(JSONObject obj, String code, boolean isSucceed) {
                            try {
                                super.onFinally(obj, code, isSucceed);
                                if (TextUtils.equals("1", code)) {
                                    content=obj.getJSONObject("data").getString("linkUrl");
                                    setUrl(content);
                                } else if ("0".equals(code)) {
                                    CommonUtil.showToask(baseContext, obj.getString("msg"));
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }, true);
        }catch (Exception e){
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (web != null) {
            web.destroyDrawingCache();
            web.destroy();
        }
    }
}
